<template>
	<view class="">
		<!-- 底部分段器 -->
		<view class="row" style="margin-top: 30rpx;">
			<view class="size30 font500 minauto" :class="tabshow == 0 ? 'col_tab' : 'col0'" @click="onTab(0)">
				已发布
				<view class="mintop10" :class="tabshow == 0 ? 'tab' : ''">
				</view>
			</view>
			<view class="size30 font500 minauto" :class="tabshow == 1 ? 'col_tab' : 'col0'" @click="onTab(1)">
				审核中
				<view class="mintop10" :class="tabshow == 1 ? 'tab ' : ''">
				</view>
			</view>
		</view>
		<!-- 底部分段器 -->
		<!-- 列表 -->
		<view class="empty" style="margin-top: 300rpx;" v-if="list.length == 0">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<view class="min30_rl mintop30" v-else>
			<view v-for="(item,index) in list">
				<view class="rad2 minbottom30 row"
					style="box-shadow: 1rpx 1rpx 8rpx 2rpx rgba(206,188,172,0.24);height: 240rpx;"
					v-if="item.type == '农产品'">
					<view class="" v-if="tabshow == 0"
						style="background-color: #169E00;width: 20%;height: 55%;clip-path: polygon(50% 0%, 100% 0%, 0% 100%, 0% 50%);">
						<view class="size26 colf font500 mintop10 minleft10" style="transform: rotate(-45deg)">
							求购
						</view>
					</view>
					<view class="" v-else
						style="background-color: #BDBDBD;width: 20%;height: 55%;clip-path: polygon(50% 0%, 100% 0%, 0% 100%, 0% 50%);">
						<view class="size26 colf font500 mintop10 minleft10" style="transform: rotate(-45deg)">
							求购
						</view>
					</view>
					<view class="column" style="padding: 20rpx 30rpx 20rpx 0;width: 75%;">
						<view class="row">
							<view class="font700 size30 col0 omit1" style="align-items: flex-end;max-width: 380rpx;">
								{{ item.title }}
							</view>
							<view class="minau minright0 size26 col6 font500" v-if="tabshow == 0">
								{{ $com.format(item.create_time, 'yyyy-MM-dd') }}
							</view>
							<view class="minau minright0 size26 font500" style="color: #FF2D10;" v-else>
								审核中
							</view>
						</view>

						<view class="minto minbottom0 row">
							<view class="column" style="width: 100%;">
								<view class="row size26 font500 align minbottom16" style="color: #808080;">
									{{ item.type == 1 ? '求购类型：' : '求租类型：' }}{{ item.appletCategory.title }}
								</view>
								<view class="row size24 font500 align minbottom16" style="color: #808080;">
									{{ item.type == 1 ? '求购数量：' : '求租面积：' }}{{ item.area }}
								</view>
								<view class="row size24 font500 align omit1" style="color: #808080;width: 100%;">
									{{ item.type == 1 ? '求购发货地：' : '求租地址：' }}{{ item.address_text }}
								</view>
							</view>
							<!-- <view class="minauto minright0 minbottom0 font500 size28 disflex align"
								style="color: #885400;" v-if="tabshow == 0">
								<image src="@/static/index/delete1.png"
									style="width: 30rpx; height: 30rpx;margin-right: 6rpx;"></image>
								删除
							</view> -->
						</view>
					</view>
				</view>
				<view class="rad2 minbottom30 row"
					style="box-shadow: 1rpx 1rpx 8rpx 2rpx rgba(206,188,172,0.24);height: 240rpx;" v-else>
					<view class="" v-if="tabshow == 0"
						style="background-color: #FAB029;width: 20%;height: 55%;clip-path: polygon(50% 0%, 100% 0%, 0% 100%, 0% 50%);">
						<view class="size26 colf font500 mintop10 minleft10" style="transform: rotate(-45deg)">
							求租
						</view>
					</view>
					<view class="" v-else
						style="background-color: #BDBDBD;width: 20%;height: 55%;clip-path: polygon(50% 0%, 100% 0%, 0% 100%, 0% 50%);">
						<view class="size26 colf font500 mintop10 minleft10" style="transform: rotate(-45deg)">
							求购
						</view>
					</view>
					<view class="column" style="padding: 20rpx 30rpx 20rpx 0;width: 75%;">
						<view class="row">
							<view class="font700 size30 col0 omit1" style="align-items: flex-end;max-width: 380rpx;">
								{{ item.title }}
							</view>
							<view class="minau minright0 size26 col6 font500" v-if="tabshow == 0">
								{{ $com.format(item.create_time, 'yyyy-MM-dd') }}
							</view>
							<view class="minau minright0 size26 font500" style="color: #FF2D10;" v-else>
								审核中
							</view>
						</view>
						<view class="minto minbottom0 row">
							<view class="column" style="width: 65%;">
								<view class="row size26 font500 align minbottom16" style="color: #808080;">
									{{ item.type == 1 ? '求购类型：' : '求租类型：' }}{{ item.appletCategory.title }}
								</view>
								<view class="row size24 font500 align minbottom16" style="color: #808080;">
									{{ item.type == 1 ? '求购数量：' : '求租面积：' }}{{ item.area }}
								</view>
								<view class="row size24 font500 align omit1" style="color: #808080;">
									{{ item.type == 1 ? '求购发货地：' : '求租地址：' }}{{ item.address_text }}
								</view>
							</view>
							<view class="minauto minright0 minbottom0 font500 size28 disflex align"
								style="color: #885400;" v-if="tabshow == 0" @click="getDelBuy(item.id)">
								<image src="@/static/index/delete1.png"
									style="width: 30rpx; height: 30rpx;margin-right: 6rpx;">
								</image>
								删除
							</view>
						</view>
					</view>
				</view>
			</view>
			<view style="margin-top: 50rpx;"><u-loadmore :status="status" /></view>
		</view>
		<!-- 列表 -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabshow: 0,
				user_id: '',
				page: 1,
				status: 'loadmore',
				loadmore: [],
				list: []
			}
		},
		onLoad() {

		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			this.user_id = uni.getStorageSync('user_id');
			if (this.user_id) {
				//如果存在token
				this.getBuyList()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {
				this.$com.toast('您还未登录，正在前往登录')
				setTimeout(() => {
					this.$jump.nav('/mypackage/sign')
				}, 1000)
			}
		},
		onReachBottom() {
			if (this.page < 0) return;
			this.status = 'loading';
			this.page = ++this.page
			this.getBuyList()
			setTimeout(() => {
				console.log(this.loadmore);
				if (this.loadmore.length == 0) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			async getBuyList() {
				let {
					code,
					msg,
					data
				} = await this.$com.fetchGet("AppletUser/GetUserAskingList", {
					page: this.page,
					user_id: this.user_id,
					is_type: this.tabshow == 0 ? 1 : 0
				})
				if (code == 1) {
					if (this.page != 1) {
						this.loadmore = data.items
						for (var i = 0; i < data.items.length; i++) {
							this.list.push(data.items[i]); // 加载的数据追加在上一页后面
						}
					} else {
						this.loadmore = data.items
						this.list = data.items
					}
				} else {
					console.log(msg);
				}
			},
			async getDelBuy(id) {
				let {
					code,
					msg,
					data
				} = await this.$com.fetchDel("AppletUser/delGetUserAskingList", {
					id: id
				})
				if (code == 1) {
					this.$com.toast(msg)
					this.getBuyList()
				} else {
					console.log(msg);
				}
			},
			onTab(i) {
				this.tabshow = i
				this.page = 1
				this.getBuyList()
			}
		}
	}
</script>

<style scoped lang="less">
	.col_tab {
		color: #FAB029;
	}

	.tab {

		height: 4rpx;
		background-color: #FAB029;
		border-radius: 20rpx;
	}

	.minbottom16 {
		margin-bottom: 16rpx;
	}
</style>